<?php

namespace app\admin\command;

use other\email\etime;
use other\email\etimeEx;
use other\facebook\AnalyzeDataFacebook;
use other\orders\Abnornal;
use other\orders\Dhour;
use other\orders\Dtime;
use other\orders\StatusEx;
use spcj\DbConn;
use spcj\Statistic;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\db\Connection;
use think\db\exception\DbException;
use think\Env;
use think\Exception;
use think\Db;
use think\exception\PDOException;
use zh\LpLog;
use zh\OrderQc;

//php think notify_log_ex
class Other extends Command
{
    protected function configure()
    {
        $this->setName('other')
            ->addArgument('param')
                ->setDescription('Compress js and css file');
    }


    /**
     * 中黑
     * @param $param
     * @return void
     * @throws DbException
     * @throws Exception
     * @throws PDOException
     */
    protected function zh($param){

        $this->spcj($param);


        switch ($param){

            case 'zh_lp_log':
                $handel = new LpLog();
                $handel->run();
                break;

            case 'zh_order':
                $handel = new OrderQc();
                $handel->run();
                break;
        }
    }


    /**
     * shopify 插件的处理
     * @param $param
     * @return void
     */
    private function spcj($param){
        switch ($param){

            case 'spcj_statistic':
                $handel = new Statistic();
                $handel->run();
                break;


            case 'spcj_lp_log':
                $handel = new \spcj\LpLog();
                $handel->run();
                break;
        }
    }

    /*
     ALTER TABLE `shoping`.`orders`
ADD INDEX `dhour`(`dhour`) USING BTREE COMMENT '定时所属小时（美国）';
     */
    /**
     * @throws Exception
     */
    protected function execute(Input $input, Output $output)
    {
        $param = $input->getArgument('param');
        if ($param){
            $this->zh($param);
            switch ($param)
            {

                case 'TEST':

                    $handel = new OrderQc();
                    $handel->run();
//                    $handel = new LpLog();
//                    $handel->run();
                    break;

                    // 订单的 小时 （美国）
                case 'dhour':
                    $handel = new Dhour();
                    $handel->do();
                    break;

                    // 异常订单
                case 'abnornal':
                    $handel = new Abnornal();
                    $handel->do();
                    break;

                    // 订单 状态 处理
                case 'status':
                    $handel = new StatusEx();
                    $handel->do();
                    break;

                    // 邮件表的数据同步 和时间处理
                case 'etime':
                    $handel = new etime();
                    $handel->do();
                    break;

                    // 邮件的执行 orders 表的字段维护
                case 'etime_ex':
                    $handel = new etimeEx();
                    $handel->do();
                    break;

                    // facebook 的分析数据
                case 'ad_facebook':
                    $handel = new AnalyzeDataFacebook();
                    $handel->do();
                    break;

                    // 转一道   订单表的 美国时区时间  和 中国时区时间
                case 'order_time':
                    $handel = new Dtime();
                    $handel->do();
                    break;
            }
        }
    }
}
